package com.example.notification;

import java.util.List;

/**
 * 短信通知服务 - 与邮件通知服务有相似方法，适合提取公共接口
 */
public class SmsNotificationService {
    
    private String smsGateway;
    private String apiKey;
    private String senderId;
    
    public boolean sendNotification(String recipient, String subject, String content) {
        System.out.println("发送短信通知到: " + recipient);
        System.out.println("主题: " + subject);
        System.out.println("内容: " + content);
        
        // 模拟短信发送逻辑
        try {
            connectToSmsGateway();
            authenticateApi();
            sendSms(recipient, content);
            return true;
        } catch (Exception e) {
            System.err.println("短信发送失败: " + e.getMessage());
            return false;
        }
    }
    
    public void batchSendNotifications(List<String> recipients, String subject, String content) {
        for (String recipient : recipients) {
            sendNotification(recipient, subject, content);
        }
    }
    
    public String getNotificationStatus(String notificationId) {
        // 模拟查询短信状态
        return "SENT";
    }
    
    public boolean validateRecipient(String recipient) {
        return recipient != null && recipient.matches("\\d{11}"); // 11位数字
    }
    
    public void configure(String gateway, String key, String sender) {
        this.smsGateway = gateway;
        this.apiKey = key;
        this.senderId = sender;
    }
    
    // 短信特有的方法
    private void connectToSmsGateway() {
        System.out.println("连接到短信网关: " + smsGateway);
    }
    
    private void authenticateApi() {
        System.out.println("API认证: " + apiKey);
    }
    
    private void sendSms(String recipient, String content) {
        System.out.println("发送短信完成");
    }
    
    public void setSmsTemplate(String templateName, String template) {
        System.out.println("设置短信模板: " + templateName);
    }
    
    public List<String> getSmsHistory(String recipient) {
        // 返回短信历史
        return List.of("sms1", "sms2", "sms3");
    }
    
    public double getSmsCost(String recipient, String content) {
        // 计算短信费用
        return content.length() * 0.1;
    }
}